//
//  DrawViewController.m
//  test02
//
//  Created by lzh on 2020/10/22.
//  Copyright © 2020 NO. All rights reserved.
//

#import "DrawViewController.h"

@interface DrawViewController ()

@end

@implementation DrawViewController

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
  
    if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
      self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    }
    
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];

    if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
       self.navigationController.interactivePopGestureRecognizer.enabled = YES;
     };
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //底部效果
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIBezierPath * path = [UIBezierPath bezierPath];
    
    [path moveToPoint:CGPointMake(0, self.view.bounds.size.height - 100)];
    [path addLineToPoint:CGPointMake(0, self.view.bounds.size.height)];
    [path addLineToPoint:CGPointMake(self.view.bounds.size.width, self.view.bounds.size.height)];
    [path addLineToPoint:CGPointMake(self.view.bounds.size.width, self.view.bounds.size.height - 100)];
    // 控制点控制曲线。一个控制点
    [path addQuadCurveToPoint:CGPointMake(0, self.view.bounds.size.height - 100) controlPoint:CGPointMake(self.view.bounds.size.width/2.0, self.view.bounds.size.height-140)];
    
    //两个控制点 画曲线
//    [path addCurveToPoint:CGPointMake(0, self.view.bounds.size.height - 100) controlPoint1:CGPointMake(self.view.bounds.size.width/2.0-150, self.view.bounds.size.height-140) controlPoint2:CGPointMake(self.view.bounds.size.width/2.0+150, self.view.bounds.size.height-140)];
    
    CAShapeLayer * zh_layer = [[CAShapeLayer alloc]init];
    
    zh_layer.lineWidth = 2.0;
    zh_layer.path = path.CGPath;
    zh_layer.strokeColor = [UIColor blackColor].CGColor;
    zh_layer.fillColor = [UIColor redColor].CGColor;
    
    [self.view.layer addSublayer:zh_layer];
    
    //三角形
    
    UIBezierPath * path1 = [UIBezierPath bezierPath];
    
    [path1 moveToPoint:CGPointMake(self.view.bounds.size.width/2.0, 100)];
    [path1 addLineToPoint:CGPointMake(self.view.bounds.size.width/2.0-50, 200)];
    [path1 addLineToPoint:CGPointMake(self.view.bounds.size.width/2.0+50, 200)];
    [path1 closePath];
    
    CAShapeLayer * layer = [[CAShapeLayer alloc]init];
    
    layer.strokeColor = [UIColor blueColor].CGColor;
//    layer.lineWidth = 2.0;
    layer.fillColor = [UIColor clearColor].CGColor ;
    layer.path = path1.CGPath;

    [self.view.layer addSublayer:layer];
    
    
#pragma mark 第一种方法 画图片圆角

    UIImageView * imageV = [[UIImageView alloc]initWithFrame:CGRectMake(10, 320, 150, 150)];
    
    imageV.image = [UIImage imageNamed:@"1"];
    
    UIBezierPath * p_path = [UIBezierPath bezierPathWithRoundedRect:imageV.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(20, 20)];
    
    CAShapeLayer * im_layer = [[CAShapeLayer alloc]init];
    
    im_layer.path = p_path.CGPath;
    
    imageV.layer.mask = im_layer;
    
    [self.view addSubview:imageV];
    
#pragma mark 第二种方法 画图片圆角
    UIImageView * imageV2 = [[UIImageView alloc]initWithFrame:CGRectMake(180, 320, 150, 150)];
    
    imageV2.image = [UIImage imageNamed:@"1"];
    
    //开始对imageView进行画图
    
    UIGraphicsBeginImageContextWithOptions(imageV2.bounds.size, NO, [UIScreen mainScreen].scale);
    
    //使用贝塞尔曲线画出一个圆形图
    
    [[UIBezierPath bezierPathWithRoundedRect:imageV2.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(20, 20)] addClip];
    
    [imageV2 drawRect:imageV2.bounds];
    
    imageV2.image = UIGraphicsGetImageFromCurrentImageContext();
    //结束画图
    UIGraphicsEndImageContext();
    
    [self.view addSubview:imageV2];

    
    
    
    
    
    
    
}



@end
